package cn.wb.base.service.impl;

import cn.wb.base.enm.ShopStateEnum;
import cn.wb.base.service.EchartsService;
import cn.wb.base.vo.EchartsMiddleVo;
import cn.wb.base.vo.EchartsVo;
import cn.wb.org.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EchartsServiceImpl implements EchartsService {

    @Autowired
    private ShopMapper shopMapper;

    @Override
    public EchartsVo echarts() {
        EchartsVo vo = new EchartsVo();
        // 查询集合数据
        List<EchartsMiddleVo> middleVoList = shopMapper.echarts();
        // 数据处理
        List<String> x = middleVoList.stream().map(middle -> ShopStateEnum.getNameByCode(middle.getX())).collect(Collectors.toList());
        vo.setX(x);
        List<Integer> y = middleVoList.stream().map(EchartsMiddleVo::getY).collect(Collectors.toList());
        vo.setY(y);
        return vo;
    }
}
